import requests
import time

def get_image():
    with open("东方财富.text", 'w', encoding='utf8') as f:
        for i in  range(1,282):
            url = f"https://42.push2.eastmoney.com/api/qt/clist/get?cb=jQuery112404808530809023055_1718877360859&pn={i}&pz=20&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&dect=1&wbp2u=|0|0|0|web&fid=f3&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23,m:0+t:81+s:2048&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152&_=1718877360895"
            response = requests.get(url)
            # print(response)
            # print(type(response))
            r = response.content.decode()
            l = r.split('jQuery112404808530809023055_1718877360859')
            l1= l[1].split('(')
            l2=l1[1].split(')')
            # print(l2[0])
            d0 = eval(l2[0])
            # print(type(d0))
            data = d0["data"]
            # print(data)
            diff = data["diff"]
            # print(diff)
            # print(type(diff))


            for i in diff:
                # print(i,type(i))
                # print(i['f12'],i['f14'])
                code = i['f12']
                name = i['f14']
                print(f'正在写入{name}')

                f.write(code)
                f.write(name)
                f.write('\n')
            time.sleep(1)





get_image()